<template>
  <div class="pd30 ele-detail-files">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>电梯列表</div>
      </div>
      <div class="bind-main">
        <div class="pl bind-top flex">
          <div class="flex flexac">
            <div class="flex flexac ">
              <el-input v-model="param.registerCode" class="reg-input" type="number" placeholder="请输入注册代码" @input="getEleDetailList" />
            </div>
            <div class="rescueCode flex flexac m-l-20">
              <el-input v-model="param.rescueCode" class="res-input co-input" placeholder="请输入位置码" @input="getEleDetailList" />
            </div>
            <div class="groupbtn flex m-l-40 ">
              <el-button class="flex flexac m-r-20 fs14" size="small" type="warning" @click="getEleDetailList"><i class="co-i" /><span class="search1">查 询</span></el-button>
              <el-button class=" co-empty flexcenter m-l-25" type="info" @click="handleEmptySearch"><i class="iconfont icon-qingkong" />清 空</el-button>
            </div>
          </div>
        </div>
        <div class="con-row flex flexac flexjcsb pl">
          <div>
            <el-button class="defaultbtn" type="primary" @click="handleRefresh"><i class="el-icon-refresh" :class="refresh?'goRefresh':''" />刷 新</el-button>

          </div>
          <div class="m-r-25 flex">

            <el-button class="defaultbtn" type="primary" @click="handleExportExcel"><i class="iconfont icon-wenjiandaochu" />导出</el-button>
            <div class="pre m-l-10">
              <el-button class="defaultbtn pre" type="primary" @click="handleSenior('field')"><i class="iconfont icon-lie" />字段
              </el-button>
              <div class="selectUl br1" :class="seniorSet.field?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" :key="i" class="li">
                  <el-checkbox v-model="item.isShow">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
            <div class="pre m-l-10">
              <el-button class="defaultbtn" type="primary" @click="handleSenior('sortable')"><i class="iconfont icon-paixu" />排序</el-button>
              <div class="selectUl br1" :class="seniorSet.sortable?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" v-if="item.isShow" :key="i" class="li">
                  <el-checkbox v-model="item.sortable">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
          </div>
        </div>
        <el-table
          id="eledetaillist"
          ref="eledetaillist"
          class="con-table"
          type="expand"
          :data="eledetaillist"
          style="width: 100%"
          highlight-current-row
        >
          <template v-for="(item,i) in tablehead">
            <el-table-column v-if="item.isShow" :key="i" align="center" :width="item.width" :sortable="item.sortable" :show-overflow-tooltip="true" :prop="item.prop" :label="item.label" />
          </template>
          <el-table-column label="绑定状态" align="center" width="90">
            <template slot-scope="scope">
              <span :class="`status-${scope.row.bindState}`">
                {{
                  scope.row.bindState === 0 ? '未绑定' :
                  scope.row.bindState === 1 ? '已录入' :
                  scope.row.bindState === 2 ? '已申请' :
                  scope.row.bindState === 3 ? '已绑定' :
                  scope.row.bindState === 4 ? '已拒绝' : '未确认'
                }}
              </span>
            </template>
          </el-table-column>
          <!-- prop="name" -->
          <el-table-column label="基本操作" align="center" width="120">
            <template slot-scope="scope">
              <el-button class="btn" type="primary" @click="handleDetail(scope.$index, scope.row)">
                <i class="el-icon-document m-r-5" />详 情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="paginationWrap flex "
          :current-page="paging.currentPage"
          :page-sizes="[10]"
          :page-size="paging.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="paging.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <!-- 电梯详情 -->
    <EleDetail v-model="detailVisible" :data="editData" @handleRefresh="handleRefresh" @handleCloseDialog="handleCloseDialog" />

  </div>
</template>

<script>

import EleDetail from './dialog/index'
import { showNotice, formatDateTime } from '@/utils/toolclass'
import { elevatorQueryList, elevatorDetail } from '@/api/elevator/elevator'
import { fetchModelList } from '@/api/elevator/elevatorModel'

import storage from '@/utils/storage'

export default {
  components: { EleDetail },
  props: {},
  data() {
    return {
      detailVisible: false,
      paging: {
        currentPage: 1,
        pageSize: 10,
        pageSizeArr: [10],
        total: 0
      },
      eledetaillist: [],
      param: {
        bindState: '',
        id: '',
        registerCode: '',
        registerUnit: '',
        rescueCode: '',
        maintenanceUnitId: '',
        useUnitId: ''
      },
      editData: {},
      refresh: false,
      seniorSet: {
        'field': false,
        'sortable': false
      },
      tablehead: [
        {
          index: 0,
          prop: 'index',
          label: '序号',
          width: '70',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 1,
          prop: 'rescueCode',
          label: '救援代码',
          width: '80',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 2,
          prop: 'registerCode',
          label: '注册代码',
          width: '200',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 3,
          prop: 'usePlaceName',
          label: '场所名称',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 4,
          prop: 'useUnitName',
          label: '使用单位',
          width: '100',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 5,
          prop: 'installAddress',
          label: '安装地址',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 6,
          prop: 'maintenancePerson1',
          label: '第一维保人',
          width: '100',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 7,
          prop: 'maintenancePerson1Phone',
          label: '第一维保人手机号码',
          width: '160',
          sortable: false,
          fixed: true,
          isShow: true
        }
      ]
    }
  },
  computed: {},
  watch: {},
  created() {
    this.userInfo = JSON.parse(storage.get('userInfo'))
    this.getEleDetailList()
  },
  mounted() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/intelligentVillage/intMonitoring/eleFileDetails' }))
  },
  methods: {
    handleDetail(index, row) {
      this.detailVisible = true
      // console.log(row)
      this.editData = {
        registerCode: row.registerCode,
        installAddress: row.installAddress === null ? '湖南省张家界市飞桥湾' : row.installAddress,
        useUnitId: row.useUnitId,
        useUnitName: row.useUnitName === null ? '熙城春天' : row.useUnitName,
        maintenanceUnitId: row.maintenanceUnitId,
        maintenanceUnitName: row.maintenanceUnitName === null ? '信富物业' : row.maintenanceUnitName,
        dateProduction: '2020-03-11', // 设备出厂日期
        modificationDate: '2020-05-24', // 设备改造日期
        installDate: '2020-07-23', // 设备安装日期
        emergencyCall: '13936898826', // 应急救援电话
        floorNumber: '20层', // 层站数
        ratedSpeed: '1.75m/s', // 额定速度
        ratedCapacity: '1300kg/13人', // 额定载重量
        showFloor: '8楼', // 显示楼层
        factoryNumber: '61345301022376489576', // 设备出厂编号
        equipmentType: '拽引驱动乘客电梯', // 设备品种
        equiModel: '商用客梯', // 设备型号
        manufacturer: '康力电梯', // 设备制造商
        interNumber: '6号梯', // 设备内部编号
        remakeUnit: '康力电梯', // 设备改造单位
        agent: '康力电梯', // 进口设备代理商
        installUnit: '康力电梯长沙分公司' // 设备安装单位
      }
    },
    getEleDetailList() {
      elevatorQueryList(this.param.bindState, this.param.id, this.param.maintenanceUnitId, this.paging.currentPage, this.paging.pageSize, this.param.registerCode, this.param.registerUnit, this.param.rescueCode, this.param.useUnitId).then((res) => {
        if (res.code === '000000') {
          // console.log(res)
          this.eledetaillist = res.data.map((item, i) => {
            const items = {
              index: i + 1,
              bindState: item.bindState,
              carNo: item.carNo,
              factoryNo: item.factoryNo,
              id: item.id,
              installAddress: item.installAddress,
              internaNo: item.internaNo,
              maintenancePerson1: item.maintenancePerson1,
              maintenancePerson1Phone: item.maintenancePerson1Phone,
              maintenanceUnitId: item.maintenanceUnitId,
              maintenanceUnitName: item.maintenanceUnitName,
              manufacturerUnitId: item.manufacturerUnitId,
              manufacturerUnitName: item.manufacturerUnitName,
              nextInspectionDate: item.nextInspectionDate,
              operator: item.operator,
              registerCode: item.registerCode,
              registerDate: item.registerDate,
              registerUnit: item.registerUnit,
              registerUpdateDate: item.registerUpdateDate,
              remark: item.remark,
              rescueCode: item.rescueCode,
              usePlaceName: item.usePlaceName,
              useUnitId: item.useUnitId,
              useUnitName: item.useUnitName,
              version: item.version,
              villageId: item.villageId,
              villageName: item.villageName
            }
            return items
          })
          this.paging = {
            pageSize: res.pager.pageSize,
            currentPage: res.pager.pageIndex,
            total: res.pager.totalSize
          }
        }
      })
    },
    handleEmptySearch() {
      this.param.registerCode = ''
      this.param.rescueCode = ''
      this.param.maintenanceUnitId = ''
      this.param.useUnitId = ''
      this.getEleDetailList()
    },
    handleSenior(type) {
      if (type === 'field') {
        this.seniorSet.field = !this.seniorSet.field
        this.seniorSet.sortable = false
      }
      if (type === 'sortable') {
        this.seniorSet.field = false
        this.seniorSet.sortable = !this.seniorSet.sortable
      }
    },
    handleExportExcel() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('@/excel/Export2Excel')
        const tHeader = ['ID', '救援代码', '注册代码', '场所名称', '使用单位', '安装地址', '第一维保人', '第一维保人手机号码', '绑定状态']
        const filterVal = ['id', 'rescueCode', 'registerCode', 'usePlaceName', 'useUnitName', 'installAddress', 'maintenancePerson1', 'maintenancePerson1Phone', 'bindState']
        const data = this.formatJson(filterVal, this.eledetaillist)
        export_json_to_excel(tHeader, data, '电梯列表(' + formatDateTime().ymd) + ')'
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    handleRefresh() {
      this.refresh = true
      this.getEleDetailList()
      setTimeout(() => {
        this.refresh = false
      }, 1200)
    },
    handleCloseDialog() {
      this.detailVisible = !this.detailVisible
    },
    handleSizeChange(val) {
      this.paging.pageSize = val
      this.getEleDetailList()
    },
    handleCurrentChange(val) {
      this.paging.currentPage = val
      this.getEleDetailList()
    }
  }
}
</script>
<style scoped lang="scss">
.ele-detail-files {
  .bind-main {
    .btn {
      width: 78px;
      height: 34px;
      line-height: 6px;
      font-size: 12px;
      vertical-align: middle;
    }
    .status-0 {
      color: red;
      font-size: 16px;
      font-weight: 700;
    }
    .status-1 {
      color: darkgoldenrod;
      font-size: 16px;
      font-weight: 700;
    }
    .status-2 {
      color: blue;
      font-size: 16px;
      font-weight: 700;
    }
    .status-3 {
      font-size: 16px;
      font-weight: 700;
    }
    .status-4 {
      font-size: 16px;
      font-weight: 700;
    }
    .status-5 {
      font-size: 16px;
      font-weight: 700;
    }
    .btn-0 {}
    .btn-1 {
      background: silver;
      color: #ffffff;
    }
    .btn-2 {
      background: silver;
      color: #ffffff;
    }
    .btn-3 {
      background: #67C23A;
      color: #ffffff;
    }
    .btn-4 {}
    .btn-5 {
      color: #ffffff;
    }
    .bind-top {
      height: 80px;
      background: #eeeeee;
      .reg-name {}
      .res-name {}
      .unit-name {}
      .reg-input {
        width: 200px;
      }
      .co-input {
        width: 180px !important;
      }
    }
  }
}
</style>
